<template>
  <div>
    <el-dialog :title="dialog.title" :visible.sync="dialog.show">
      <el-form :model="form" :rules="rules" ref="perRef">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="标识" prop="code">
          <el-input v-model="form.code"></el-input>
        </el-form-item>
        <el-form-item label="描述" prop="description">
          <el-input v-model="form.description"></el-input>
        </el-form-item>
        <el-form-item label="开启">
          <el-switch
            v-model="form.enVisible"
            active-color="#13ce66"
            inactive-color="#ff4949"

          ></el-switch>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button>取消</el-button>
        <el-button type="primary" @click="btnok">确定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {addpermissionAPI,updatapermissionAPI}from "@/api/permission"
export default {
    props:{
        dialog:{
            type:Object,
            require:true
        },
        form:{
            type:Object,
            require:true
        },
    },
    data() {
        return {
            rules:{
                name:[{
                    require:true,message:"名称不能为空",trigger:'blur'
                }],
                code:[{
                    require:true,message:"标识不能为空",trigger:'blur'
                }],
            }
        }
    },
    methods:{
        btnok(){
            this.$refs.perRef.vaildate(async isok=>{
                if(isok){
                    if(this.dialog.option==='add'){
                        await addpermissionAPI(this.form)
                        this.$message.success('添加成功')
                    }else{
                        await updatapermissionAPI(this.form)
                        this.$message.success('修改成功')
                    }
                    this.dialog.show = false
                    this.$emit('update')
                }
            })
        }
    }
};
</script>

<style scoped></style>
